var mScript = document.createElement('script');
mScript.innerHTML = `let divDom = document.getElementById('tab-uname');
if (divDom && divDom.innerText == '账号密码登录') {
    autoLogin();
} else {
    setTimeout(checkTarget, 2000);
}


function autoLogin() {

    var inputEvent = new Event('input', {
        bubbles: true,
        cancelable: true
    });
    let sign1 = false, sign2 = false;
    for (const e of document.querySelectorAll('input')) {
        if (e.placeholder == '账号') {
            e.value = 'wuyunqing01';
            sign1 = true;
            e.dispatchEvent(inputEvent);
        }
        if (e.placeholder == '密码') {
            e.value = 'wuyunqing@6';
            sign2 = true;
            e.dispatchEvent(inputEvent);
        }
        if (sign1 && sign2) {
            for (const span of document.querySelectorAll('span')) {
                if (span.innerText === '登 录') {
                    span.parentElement.click();
                    setTimeout(checkTarget, 700);
                    break;
                }
            }
            break;
        }
    }
}

function checkTarget() {
    let sign = true;
    for (const ele of document.querySelectorAll('span')) {
        if (ele.innerText === '发布产品') {
            let obj = ele.parentElement;
            if (obj && obj.tagName && obj.tagName.toUpperCase() === 'LI') {
                obj.click();
                setTimeout(createRouteID, 700);
                sign = false;
                break;
            }
        }
    }
    if (sign) {
        setTimeout(checkTarget, 200);
    }
}

function createRouteID() {
    //点击'线路'类型
    let sign = true;
    for (const ele of document.querySelectorAll('div')) {
        if (ele.innerText.replace(/\s|\\n/g, '') === '线路专指需要签署旅游合同，提供标准化服务的跟团旅游产品。') {
            ele.click();
            sign = false;
            //点击'下一步'
            for (const next of document.querySelectorAll('span')) {
                if (next.innerText.replace(/\s/g, '') === '下一步') {
                    console.log(next);
                    next.parentElement.click();
                    setTimeout(() => {
                        autoFillInfo();
                    }, 1000);
                    break;
                }
            }
            break;
        }
    }
    if (sign) {
        setTimeout(createRouteID, 200);
    }
}

function selectOption(placeholder, targetValue) {
    const input = Array.from(document.querySelectorAll('input'));
    // if (input) {
    //     input.dispatchEvent(inputEvent);

    //     const targetLi = Array.from(document.querySelectorAll('li')).find(li => li.innerHTML === `<span>${targetValue}</span>`);
    //     if (targetLi) {
    //         targetLi.click();
    //     }
    // }
}

function autoFillInfo() {
    var inputEvent = new Event('input', {
        bubbles: true,
        cancelable: true
    });
    Promise.resolve().then(() => {
        //选择供应商
        console.log('1');
        for (const input of document.querySelectorAll('input')) {
            if (input.placeholder === '请选择供应商') {
                // input.value = '佛山旅游有限公司';
                input.dispatchEvent(inputEvent);
                for (const li of document.querySelectorAll('li')) {
                    if (li.innerHTML === '<span>佛山旅游有限公司</span>') {
                        li.click();
                        break;
                    }
                }
                break;
            }
        }
    }).then(() => {
        console.log('2');
        for (const input of document.querySelectorAll('input')) {
            if (input.placeholder === '请选择线路类型') {
                // input.value = '佛山旅游有限公司';
                input.dispatchEvent(inputEvent);
                for (const li of document.querySelectorAll('li')) {
                    if (li.innerHTML === '<span>周边游</span>') {
                        li.click();
                        break;
                    }
                }
                break;
            }
        }
    }).then(() => {
        console.log('3');
        for (const input of document.querySelectorAll('input')) {
            if (input.placeholder === '请选择线路区域') {
                // input.value = '佛山旅游有限公司';
                input.dispatchEvent(inputEvent);
                for (const li of document.querySelectorAll('li')) {
                    if (li.innerHTML === '<span>珠三角</span>') {
                        li.click();
                        break;
                    }
                }
                break;
            }
        }
    }).then(() => {
        console.log('3');
        for (const input of document.querySelectorAll('input')) {
            if (input.placeholder === '请选择出游方式') {
                // input.value = '佛山旅游有限公司';
                input.dispatchEvent(inputEvent);
                for (const li of document.querySelectorAll('li')) {
                    if (li.innerHTML === '<span>拼团</span>') {
                        li.click();
                        break;
                    }
                }
                break;
            }
        }
    }).then(() => {
        console.log('6');
        for (const input of document.querySelectorAll('input')) {
            if (input.placeholder === '请选择出发城市') {
                // input.value = '佛山旅游有限公司';
                input.dispatchEvent(inputEvent);
                for (const li of document.querySelectorAll('li')) {
                    if (li.innerHTML === '<span>佛山</span>') {
                        li.click();
                        input.click();
                        break;
                    }
                }
                break;
            }
        }
    })

}



`;
        document.head.appendChild(mScript);